package labox.innovation.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javolution.util.FastList;

import labox.innovation.util.L2Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NpcConfig {
    private static final Logger _log = LoggerFactory.getLogger(NpcConfig.class.getName());

    private static final String NPC_CONFIG_FILE = "./config/npc.properties";
    // --------------------------------------------------
    // NPC Settings
    // --------------------------------------------------
    public static boolean ANNOUNCE_MAMMON_SPAWN;

    public static boolean ALT_MOB_AGRO_IN_PEACEZONE;

    public static boolean ALT_GAME_VIEWNPC;

    public static int MAX_DRIFT_RANGE;

    public static boolean DEEPBLUE_DROP_RULES;

    public static boolean DEEPBLUE_DROP_RULES_RAID;

    public static boolean SHOW_NPC_LVL;

    public static boolean GUARD_ATTACK_AGGRO_MOB;

    public static boolean ALLOW_WYVERN_UPGRADER;

    public static String PET_RENT_NPC;

    public static List<Integer> LIST_PET_RENT_NPC = new FastList<Integer>();

    public static int RAID_MINION_RESPAWN_TIMER;

    public static boolean RAID_DISABLE_CURSE;

    public static int INVENTORY_MAXIMUM_PET;

    public static void load() {
        _log.info("Loading npc Configuration Files...", Config.SERVER_ID);
        InputStream is = null;
        try {
            L2Properties NPC = new L2Properties();
            is = new FileInputStream(new File(NPC_CONFIG_FILE));
            NPC.load(is);

            ANNOUNCE_MAMMON_SPAWN = Boolean.parseBoolean(NPC.getProperty("AnnounceMammonSpawn", "False"));
            ALT_MOB_AGRO_IN_PEACEZONE = Boolean.parseBoolean(NPC.getProperty("AltMobAgroInPeaceZone", "True"));

            ALT_GAME_VIEWNPC = Boolean.parseBoolean(NPC.getProperty("AltGameViewNpc", "False"));
            MAX_DRIFT_RANGE = Integer.parseInt(NPC.getProperty("MaxDriftRange", "300"));
            DEEPBLUE_DROP_RULES = Boolean.parseBoolean(NPC.getProperty("UseDeepBlueDropRules", "True"));
            DEEPBLUE_DROP_RULES_RAID = Boolean.parseBoolean(NPC.getProperty("UseDeepBlueDropRulesRaid", "True"));
            SHOW_NPC_LVL = Boolean.parseBoolean(NPC.getProperty("ShowNpcLevel", "False"));

            GUARD_ATTACK_AGGRO_MOB = Boolean.parseBoolean(NPC.getProperty("GuardAttackAggroMob", "False"));
            ALLOW_WYVERN_UPGRADER = Boolean.parseBoolean(NPC.getProperty("AllowWyvernUpgrader", "False"));
            PET_RENT_NPC = NPC.getProperty("ListPetRentNpc", "30827");
            LIST_PET_RENT_NPC = new FastList<Integer>();
            for (String id : PET_RENT_NPC.split(",")) {
                LIST_PET_RENT_NPC.add(Integer.parseInt(id));
            }
            RAID_MINION_RESPAWN_TIMER = Integer.parseInt(NPC.getProperty("RaidMinionRespawnTime", "300000"));
            RAID_DISABLE_CURSE = Boolean.parseBoolean(NPC.getProperty("DisableRaidCurse", "False"));
            INVENTORY_MAXIMUM_PET = Integer.parseInt(NPC.getProperty("MaximumSlotsForPet", "12"));

        } catch (Exception e) {
            _log.error("Failed to Load " + NPC_CONFIG_FILE + " File.", e);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                _log.error("InputStream close occured IOException");
            }
        }
    }
}
